package com.xoms.admin.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.ProDepositBean;
import com.xoms.admin.model.ProDepositDetailBean;
import com.xoms.admin.persist.dao.ProDepositDao;
import com.xoms.util.StringUtil;

@Repository
public class ProDepositImpl extends BaseImpl implements ProDepositDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".ProDepositMapper";

	@Override
	public int selectCount(String startTime, String endTime, String storeId) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(startTime)) {
			params.put("startTime", startTime);
		}
		if (!StringUtil.isEmpty(endTime)) {
			params.put("endTime", endTime);
		}
		if (!StringUtil.isEmpty(storeId)) {
			params.put("storeHouseId", storeId);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", params);

	}

	@Override
	public List<ProDepositBean> selectList(int page, int pageSize, String startTime, String endTime, String storeId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		if (!StringUtil.isEmpty(startTime)) {
			params.put("startTime", startTime);
		}
		if (!StringUtil.isEmpty(endTime)) {
			params.put("endTime", endTime);
		}
		if (!StringUtil.isEmpty(storeId)) {
			params.put("storeHouseId", storeId);
		}
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);

	}

	@Override
	public int selectDetailCount(String key, String did) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		if (!StringUtil.isEmpty(did)) {
			params.put("did", did);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectDetailCount", params);
	
	}

	@Override
	public List<ProDepositDetailBean> selectDetailList(String key, String did, int page, int pageSize, int paging) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		if (!StringUtil.isEmpty(did)) {
			params.put("did", did);
		}
		params.put("paging", paging);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectDetailList", params);

	}


}
